<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">

    /**
     * 自定义验证规则
     */
    function validateForm() {
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                trueName: {
                    validators: {
                        notEmpty: {message: "真实姓名不可为空"},
                        stringLength: {max: 20, message: "真实姓名最大长度为20"},
                        regexp: {
                            regexp: validateUtil.chinese,
                            message: '真实姓名为汉字'
                        }
                    }
                },
                nikeName: {
                    validators: {
                        notEmpty: {message: "昵称不可为空"},
                        stringLength: {max: 50, message: "昵称最大长度为50"}
                    }
                },
                qq: {
                    validators: {
                        notEmpty: {message: "QQ号码不可为空"},
                        stringLength: {max: 15, message: "QQ号码最大长度为15"},
                        regexp: {
                            regexp: validateUtil.qq,
                            message: 'qq号码格式错误'
                        }
                    }
                },
                mobile: {
                    validators: {
                        notEmpty: {message: "手机号不可为空"},
                        regexp: {
                            regexp: validateUtil.phone,
                            message: '手机号码格式错误'
                        }
                    }
                },
                phone: {
                    validators: {
                        notEmpty: {message: "电话号码不可为空"},
                        regexp: {
                            regexp: validateUtil.tel,
                            message: '联系电话格式错误'
                        }
                    }
                },
                workNumber: {
                    validators: {
                        notEmpty: {message: "工作号不可为空"},
                        stringLength: {min: 2,max: 6,message: "工作号长度为2至6"},
                        regexp: {
                            regexp: validateUtil.onlyCharAndNumber,
                            message: '只能填写字母或者数字'
                        }
                    }
                }
            }
        });
    }

    /**
     * 编辑店铺客服信息
     */
    function editInfo() {
        $("#myModalLabel").empty().text("修改店铺客服信息");
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            var id = selectedRow[0].customerServiceId;
            $("#btn_edit").attr("data-target", "#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/customerService/getCustomerServiceInfo.sjson",
                data: {customerServiceId: id},
                success: function (result) {
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#shopInfoId").val(data[0].shopInfoId);
                    $("#customerServiceId").val(data[0].customerServiceId);
                    $("#imageUrl_1").val(data[0].photoUrl);
                    /**可见表单控件**/
                    $("#workNumber").val(data[0].workNumber);
                    $("#trueName").val(data[0].trueName);
                    $("#nikeName").val(data[0].nikeName);
                    $("#mobile").val(data[0].mobile);
                    $("#phone").val(data[0].phone);
                    $("#qq").val(data[0].qq);
                    $("#useState_" + data[0].useState).attr("checked", "checked");

                    /**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
                    initImageForUpdate(1,"sys_shop", "image_shopInfo", 1, 36, 36, "${uploadPath}", data[0].photoUrl);
                    reValidateForm();
                    removeValidateField('imageInfo_1');
                }
            });
        } else {
            $("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }

    /**添加店铺客服信息**/
    function addInfo(){
        $("#myModalLabel").empty().text("添加自营店铺客服信息");
        $("#btn_add").attr("data-target", "#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
        /**清空隐藏域的值**/
        $("#customerServiceId").val("");
        $("#imageUrl_1").val("");
        resetAddForm();
        /**如果有上传图片功能添加此代码，否则可以去掉**/
        initImageForAdd(1,"sys_shop", "image_shopInfo", 1, 36, 36);
    }

</script>
<!--编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:60%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h5 class="modal-title" id="myModalLabel"></h5>
            </div>

            <div class="modal-body">
                <form id="form1" method="post" action="${basePath}/back/customerService/saveOrUpdateCustomerService.sjson">
                    <input id="shopInfoId" type="hidden" name="shopInfoId" value="${shopInfoId}"/>
                    <input id="customerServiceId" type="hidden" name="customerServiceId" noclear="true"/>
                    <table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
                        <tr>
                            <td class="toright_td"><span style="color:red">* </span>客服头像:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="container">
                                    <input id="imageUrl_1" type="hidden" name="photoUrl" value=""/>
                                    <div class="form-group" id="fileWrap1"></div>
                                </div>
                                <span style="color:red">提示：请上传规格宽36px，高36px的图片</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>真实姓名:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="trueName" name="trueName" placeholder="请输入真实姓名"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>昵称:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="nikeName" name="nikeName" placeholder="请输入昵称"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>QQ号码:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="qq" name="qq" placeholder="请输入QQ号码"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>手机号:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="mobile" name="mobile" placeholder="请输入手机号"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>电话号码:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="phone" name="phone" placeholder="请输入电话号码"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>工作号:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <div class="form-group">
                                    <input type="text" class="form-control input-sm" id="workNumber" name="workNumber" placeholder="请输入工作号"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="toright_td" width="150px"><span style="color:red">* </span>是否废弃:&nbsp;&nbsp;</td>
                            <td class="toleft_td">
                                <label class="checkbox-inline">
                                    <input type="radio" name="useState" id="useState_1" class="radioInput" value="1" checked="checked">&nbsp;正常使用
                                </label>
                                <label class="checkbox-inline">
                                    <input type="radio" name="useState" id="useState_0" class="radioInput" value="0">&nbsp;废弃
                                </label>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" id="validateBtn2" class="btn btn-primary"  onclick="submitForm()">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
